#include "punct_stream.h"
bool Punct_stream::is_whitespace(char c) const
{
    return white.find(c) != std::string::npos;
}

Punct_stream &Punct_stream::operator>>(std::string &s)
{
    while (!(buffer >> s))
    {
        if (buffer.bad() || !source)
        {
            return *this;
        }
        buffer.clear();
        std::string line;
        std::getline(source, line);
        for (char &ch : line)
        {
            if (is_whitespace(ch))
            {
                ch = ' ';
            }
            else if (!sensitive)
            {
                ch = tolower(ch);
            }
        }
        buffer.str(line);
    }
    return *this;
}

Punct_stream::operator bool() const
{
    return bool(source);
}